package com.housekeeping.housekeeping.cleanerInformation.utils;

import java.io.Serializable;

/**
 * @author hua
 * @version JDK1.8
 * @date 2021/1/23 9:13
 * 图片上传后回调json数据
 */
public class ResponseImages<T> implements Serializable {//实现序列化接口
    //状态码
    private int code;
    //回调信息
    private String msg;
    //要传输的数据 T 是指泛型
    private T data;

    //成功的回调
    public static<T> ResponseImages<T> success(T data){
        ResponseImages<T> images = new ResponseImages<>();
        //设置要响应给前端的数据, 都存放在data中
        images.setData(data);
        //设置响应给前端的状态码
        images.setCode(200);
        //要响应给前端的消息
        images.setMsg("success");
        //返回封装好的对象
        return images;
    }

    //请求失败的回调,  参数1失败的状态码,  参数2失败后要响应给前端的消息
    public static<T> ResponseImages<T> error(int code, String msg){
        ResponseImages<T> images = new ResponseImages<>();
        images.setCode(code);
        images.setMsg(msg);
        return images;
    }

    public ResponseImages() {
    }

    public ResponseImages(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
